window.onload = function () {
    var province = ['上海', '江西', '江苏'];
    var city = [['浦东新区', '宝山区', '静安区'], ['南昌', '宜春', '赣州'], ['南京', '苏州', '无锡']];
    var county = [[['川沙镇', '唐镇', '金沙镇'], ['顾村镇', '刘行镇', '罗店镇'], ['静安一区', '静安二区', '静安三区']],
    [['南昌县', '安义县', '鄱阳县'], ['袁州区', '奉新县', '高安市'], ['赣州一区', '赣州二区', '赣州三区']],
    [['南京一区', '南京二区', '南京三区'], ['苏州一区', '苏州二区', '苏州三区'], ['无锡一区', '无锡二区', '无锡三区']]];
    // var provinceSel = window.province;
    var provinceSel = document.getElementById('province');
    // var citySel = window.city;
    var citySel = document.getElementById('city');
    // var countySel = window.county;
    var countySel = document.getElementById('county');
    // console.log(provinceSel)
    var provinceIndex;
    var cityIndex;

    province.forEach((val, i) => {
        var op = new Option();
        // var op = document.createElement('option');
        op.innerHTML = val;
        op.value = i;
        provinceSel.appendChild(op);
    })
    city[0].forEach((val, i) => {
        var op = new Option();
        op.innerHTML = val;
        op.value = i;
        citySel.appendChild(op);
    })
    county[0][0].forEach((val, i) => {
        var op = new Option();
        op.innerHTML = val;
        op.value = i;
        countySel.appendChild(op);
    })

    // for (let i in province) {
    //     var op = new Option();
    //     // var op = document.createElement('option');
    //     op.innerHTML = province[i];
    //     op.value = i;
    //     provinceSel.appendChild(op);
    // }
    // for (let j in city[0]) {
    //     var op = new Option();
    //     op.innerHTML = city[0][j];
    //     op.value = j;
    //     citySel.appendChild(op);
    // }
    // for (let i in county[0][0]) {
    //     var op = new Option();
    //     op.innerHTML = county[0][0][i];
    //     op.value = i;
    //     countySel.appendChild(op);
    // }

    provinceSel.onchange = function () {
        citySel.innerHTML = '';
        countySel.innerHTML = '';
        provinceIndex = this.value;
        for (let i in city[provinceIndex]) {
            var op = new Option();
            op.innerHTML = city[provinceIndex][i];
            op.value = i;
            citySel.appendChild(op);
        }
        for (let i in county[provinceIndex][0]) {
            var op = new Option();
            op.innerHTML = county[provinceIndex][0][i];
            op.value = i;
            countySel.appendChild(op);
        }

    }

    citySel.onchange = function () {
        countySel.innerHTML = '';
        cityIndex = this.value;
        console.log(provinceIndex, cityIndex)
        for (let i in county[provinceIndex][cityIndex]) {
            var op = new Option();
            op.innerHTML = county[provinceIndex][cityIndex][i];
            op.value = i;
            countySel.appendChild(op);
        }
    }


}

